package com.kun.service_cms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kun.service_cms.entity.CrmBanner;
import com.kun.service_cms.service.CrmBannerService;
import com.kun.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author dmk
 * @since 2021-10-22
 */
@RestController
@RequestMapping("/service_cms/crm-banner")
@CrossOrigin
public class BannerAdminController {
    @Autowired
    private CrmBannerService bannerService;
    @GetMapping("pageBanner/{page}/{limit}")
    public R pageBanner(@PathVariable long page,@PathVariable long limit){
        Page<CrmBanner> pageBanner = new Page<>(page,limit);
        bannerService.page(pageBanner,null);
        return R.ok().data("items",pageBanner.getRecords()).data("total",pageBanner.getTotal());
    }
    @PostMapping("addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){
        bannerService.save(crmBanner);
        return R.ok();
    }
    @PostMapping("updateBanner")
    public R updateBanner(@RequestBody CrmBanner crmBanner){
        bannerService.updateById(crmBanner);
        return R.ok();
    }
    @PostMapping("getBannerById/{id}")
    public R getBannerById(@PathVariable String id){
        CrmBanner banner = bannerService.getById(id);
        return R.ok().data("Banner",banner);
    }
    @DeleteMapping("delBannerById/{id}")
    public R delBannerById(@PathVariable String id){
        bannerService.removeById(id);
        return R.ok();
    }
}

